<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>观察者模式</title>
  </head>
  <body>
    <script>
      const father = {
        eat() {
          console.log('不给出去玩！准备吃饭了')
        },
      }

      const son = {
        play() {
          console.log('爸，我出去玩会~')
          EventObj.dispatchEvent(new CustomEvent('callFather'))
        },
      }

      const EventObj = new EventTarget()
      EventObj.addEventListener('callFather', father.eat)

      son.play()
    </script>
  </body>
</html>
